package com.xjtu.project.common.utls;


import com.xjtu.project.model.domain.Employee;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


public class SessionUtils {
    private static final String USERKEY = "sessionEmployee";

    public static HttpSession session() {
        ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        return attr.getRequest().getSession(true); // true == allow create
    }

    public static Employee getCurrentEmployeeInfo() {
        return (Employee) session().getAttribute(USERKEY);
    }

    public static void saveCurrentEmployeeInfo(Employee admin) {
        session().setAttribute(USERKEY, admin);
    }
}
